
import { Request_API_COM } from 'index.js'
import regeneratorRuntime from '../plugins/regenerator-runtime.js'


;export const addVisitorPerson = (e)=>{
  if (e.AID && typeof e.AID != undefined) {//访客人数
  console.log(e)
    // console.log(e)
    //投放外链的打开人数，去重
    //假设一个人打开程序退出之后再次进入计一次
    //但是打开程序之后，如删除程序。则不纳入计算范围
    var AID = wx.getStorageSync('AID');
    if (!AID) {
      Request_API_COM('/channel/addVisitorPerson', 'POST',{ AID: e.AID })
      .then((res) => {
        console.log('访客人数')
        wx.setStorageSync('AID', e.AID)
      })
      Request_API_COM('/channel/addVisitorFrequency', 'POST', { AID: e.AID } )
      .then((res) => {
        console.log('访客次数')
      })

    }
  }
  return e
}





export const addVisitorFrequency = (e)=>{
  if(e.AID && typeof e.AID != undefined) {//访客次数
    var AID = wx.getStorageSync('AID')
    if (AID){
      Request_API_COM('/channel/addVisitorFrequency', 'POST', { AID: e.AID})
      .then((res)=>{
        console.log('访客次数')
      })
    }
  }
}


//此APPID为后台管理系统ID
//值为'shareNum(分享次数),sharePerson(分享人数),sharedPerson(通过分享新增)'
//e为index.js => onload(e) 
export const setInc = (e,id,tp)=>{
    if (e.GOpenid){
      Request_API_COM('/program_census/setInc', 'POST', { appid: id, type: tp })
      .then((res) => {
          tp == 'shareNum' ? console.log('分享次数') : (tp == 'sharePerson' ? console.log('分享人数') : tp == 'sharedPerson' ? console.log('通过分享新增') : "")
      })
    }
   
}




export const shareNumber = (e)=>{
  // console.log(e)
  if (e.SID && typeof e.SID != undefined && !wx.getStorageSync('SID')) {//访客次数
    Request_API_COM('/share/addVisitorPerson', 'POST', { SID: e.SID})
      .then((res) => {
        if(res.data.data.code==1){
          console.log('通过分享进入人数')
          wx.setStorageSync('SID', e.SID)
        }
      })
  }
  return e
}